1import { BUNDLE_DOWNLOAD_PROVIDERS } from "../../../../lib/download-providers.js";
2
3export async function onRequestGet(context) {
4 const { provider } = context.params;
5
6 if (!provider || !BUNDLE_DOWNLOAD_PROVIDERS.includes(provider)) {
7 return Response.json({ error: "Invalid provider" }, { status: 400 });
8 }
9
10 const url = new URL(context.request.url);
11 url.pathname = `/_data/dist/${provider}.zip`;
12
13 const response = await context.env.ASSETS.fetch(url);
14
15 if (!response.ok) {
16 return Response.json({ error: "Bundle not found" }, { status: 404 });
17 }
18
19 const content = await response.arrayBuffer();
20 const safeProvider = provider.replace(/[^a-zA-Z0-9._-]/g, '');
21
22 return new Response(content, {
23 headers: {
24 'Content-Type': 'application/zip',
25 'Content-Disposition': `attachment; filename="impeccable-style-${safeProvider}.zip"`,
26 'Cache-Control': 'public, s-maxage=86400, stale-while-revalidate=3600',
27 }
28 });
29}